<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/7/27 10:55
 */

namespace module\chat\front\searcher;

use module\chat\model\Message;
use module\user\library\Auth;
use mof\Request;
use mof\Searcher;

class MessageSearcher extends Searcher
{
    public function __construct(Request $request)
    {
        parent::__construct();

        $params = $request->withValidate([
            'object_type|对话类型' => 'require|in:visrole,unlimited,assistant',
            'object_id|会话ID'     => 'require|integer',
            'channel_id|通道ID'    => 'integer',
            'last_id'              => 'integer',
        ])->get(['object_type', 'object_id', 'channel_id', 'last_id']);

        $params['user_id'] = app(Auth::class)->getId();
        $params['received'] = 1;
        $this->model(new Message())->params($params)->order(['id' => 'desc']);
    }
}